﻿using System;
using System.Collections.Generic;
using System.Linq;
using WeBlog.Interfaces;
using WeBlog.Models;
using WeBlog.Repositories;

namespace WeBlog.Models {
    public class CategoryDetailsViewModel : GridModel<Post>
    {
        private readonly CategoryRepository _categoryRepository;
        public Category Category { get; private set; }

        public CategoryDetailsViewModel(GridSettings settings, IUnitOfWork unitOfWork, string name) :
            base(settings)
        {
            _categoryRepository = new CategoryRepository(unitOfWork);

            Category = _categoryRepository.FindByName(name);
            if( Category == null ) throw new NotFoundException();            
            Settings.DefaultSortColumn = "PublishDate";            
        }


        public override IQueryable<Post> GetSuperSet()
        {
            return Category.Posts.Where(x => x.Published == true).AsQueryable();
        }
	}
}